import { action, observable } from 'mobx';
import productService from '../services/product/productService';
import { ProductListDto } from '../services/product/dto/productListDto'
import { PagedList } from '../services/dto/pagedList';
import { ProductDto } from '../services/product/dto/productDto';
import { ProductPagedQueryDto } from '../services/product/dto/productPagedQueryDto';
import { ProductCommentPagedQueryDto } from '../services/product/dto/productCommentPagedQueryDto';
import { ProductCommentListDto } from '../services/product/dto/productCommentListDto';
import { ProductCommentStatisticsDto } from '../services/product/dto/productCommentStatisticsDto';
import { ProductCommentInputDto } from '../services/product/dto/ProductCommentInputDto';


class ProductStore {
    @observable products: PagedList<ProductListDto>
    @observable product: ProductDto
    @observable comments: PagedList<ProductCommentListDto>
    @observable statistics: ProductCommentStatisticsDto
    @observable productList: ProductListDto[]

    @action
    async getProductPagedListAsync(input: ProductPagedQueryDto) {
       this.products =  await productService.getProductPagedListAsync(input);
       return this.products
    }

    @action
    async getProduct(id: number) {
        await productService.getProductAsync(id).then((res) => {
            this.product = res.data.result;
        })
    }

    @action
    async getProductCommentPagedListAsync(input: ProductCommentPagedQueryDto){
        await productService.getProductCommentPagedListAsync(input).then((res) => {
            this.comments = res
        })
    }

    @action
    async getProductCommentStatisticsAsync(id: number){
        await productService.getProductCommentStatisticsAsync(id).then((res) => {
            this.statistics = res.data.result;
        })
    }

    @action
    async getProductListByIds(ids:string[]){
        await productService.getProductListByIds(ids).then((res) => {
            this.productList = res.data.result;
        })
    }

    @action
    async createProductComment(model:ProductCommentInputDto){
        await productService.createProductComment(model)
    }
}

export default ProductStore
